#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/7/6 15:08
# @Author : linjinting
# @Project : tableview-model
# @File : tableItem.py
# @Software: PyCharm


class TableItem(object):
    def __init__(self, data, parent=None):
        self.parentItem = parent
        self.itemData = data
        self.childItems = []
        # self.childIds = {}

    def appendChild(self, item):
        self.childIds[item.getItemId()] = item

        self.childItems.append(item)

    def getAllChilds(self):
        return self.childItems

    def child(self, row):
        return self.childItems[row]

    def childCount(self):
        return len(self.childItems)

    def columnCount(self):
        return len(self.itemData)
        # return 3

    def data(self, column):
        try:
            return self.itemData[column]
        except IndexError:
            return None

    def parent(self):
        return self.parentItem

    def row(self):
        if self.parentItem:
            return self.parentItem.childItems.index(self)

        return 0

    def itemdata(self):
        return self.itemData

    # def findParentItmeFromUID(self, uid):
    #     ##根据本身的UID、对应父节点的ID，找到对应的item
    #     return self.childIds.get(uid)
    #
    # def findChildItmesFromId(self, id):
    #     childs = self.getAllChilds()
    #
    #     # items = [ child for child in childs if child.itemData['parentBizOrgId'] == id]#
    #     items = []
    #     for child in childs:
    #         if child.getItemUid() == id:
    #             items.append(child)
    #
    #     # print("len:",items.size())
    #
    #     return items
    #
    # def remove(self, itme):
    #     # print(itme.itemData['bizOrgName'],self.childItems)
    #     # print("itme",itme)
    #     self.childItems.remove(itme)
    #
    # def moveChildItmes(self, items, newparent):
    #     for item in items:
    #         self.remove(item)
    #         item.parentItem = newparent
    #         newparent.appendChild(item)
    #         # self.remove(item)
    #     pass
    #
    # def getItemId(self):
    #     return self.itemData['bizOrgId']
    #
    # def getItemName(self):
    #     return self.itemData['bizOrgName']
    #
    # def getItemUid(self):
    #     return self.itemData['parentBizOrgId']

